<?php

namespace Viettrans\BackBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class DefaultController extends Controller
{
    /**
     * @Route("/bo/", name="bo_index")
     * @Template()
     */
    public function indexAction() {
		# Get the array from the text file and assign it to $admins
		$adminsRaw = $this->container->getParameter("admins");

        $adminsParsed = explode(",", $adminsRaw);
		
        $admins = array();
        
        foreach ($adminsParsed as $adminParsed){
            list($user, $pass, $role) = explode(':', $adminParsed);
            $admins[$user] = array('pass'=>$pass, 'role'=>$role);
        }
		
		$session = $this->get('session');
		
		$user = $session->get('user');
		        
		if(!$session->has('user') || !array_key_exists($user, $admins)) {
			return $this->redirect($this->generateUrl('bo_user_login'));
		}
			
		return array('user' => $user);
    }
}
